home *** CD-ROM | disk | FTP | other *** search
- Path: thor.tu.hac.com!collins
- From: collins@thor.tu.hac.com (Ron Collins)
- Newsgroups: comp.lang.c
- Subject: Re: revised code of calling a function twice from printf
- Date: 6 Mar 1996 14:57:06 GMT
- Organization: Advanced Depot Systems
- Distribution: world
- Message-ID: <4hk942$mu9@hacgate2.hac.com>
- References: <4hfs54$k4e@newsbf02.news.aol.com> <Pine.A32.3.91.960304174215.96209J-100000@black.weeg.uiowa.edu>
- NNTP-Posting-Host: thor.tu.hac.com
- X-Newsreader: TIN [version 1.2 PL2]
-
- The Amorphous Mass (robinson@blue.weeg.uiowa.edu) wrote:
- [snip]
-
- : > return 0;
- : > }
- : >
- : > char *display_drug_type(int drug_index) {
- : > char drug_type[81]="\0";
-
- : make this
- : static char drug_type[81]; /* static variables are automatically
- : initialized to 0, and it's safe to
- : return their addresses -- they "persist" */
-
-
- No ... "static" is no good here. Since he's calling "display_drug_type"
- twice within a single sequence, only the value stored in the last call
- will be returned to his "printf" statement. That is, "display_drug_type"
- will be called twice _before_ the call to "printf"; hence, he will not get
- two different strings displayed, just the same string displayed twice.
-
-
- -- collins --
-
-
-